package com.atguigu.core.controller;

import cn.hutool.core.date.DateUtil;
import com.atguigu.core.bean.R;
import com.atguigu.core.enumcode.ResultStatusCode;
import com.atguigu.core.feign.PayFeignApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order-circuit")
public class OrderCircuitController {

    @Autowired
    private PayFeignApi payFeignApi;

    @GetMapping("/get/{id}")
    public R get(@PathVariable("id") Integer id) {

        try {
            System.out.println("--------- 调用开始："+ DateUtil.now());
            return payFeignApi.gePayDto(id);
        }catch (Exception e){
            System.out.println("--------- 调用结束："+ DateUtil.now());
            e.printStackTrace();
            return  R.failure(ResultStatusCode.HTTP_ERROR_500.getMsg());
        }
    }


    @GetMapping("/get/info")
    public R getMlb() {
        return R.ok().data(payFeignApi.getInfoByConsul());
    }


    @GetMapping("/circuit/{id}")
    public R circuit(@PathVariable("id") Integer id) {

        try {
            System.out.println("--------- 调用开始："+ DateUtil.now());
            return payFeignApi.circuit(id);
        }catch (Exception e){
            System.out.println("--------- 调用结束："+ DateUtil.now());
            e.printStackTrace();
            return  R.failure(ResultStatusCode.HTTP_ERROR_500.getMsg());
        }
    }


}
